//
//  QDao.h
//  BackgroundTracker
//
//  Created by Zhang Yinghui on 12-5-3.
//  Copyright (c) 2012年 Wakefield School. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Dao.h"

#define DBQ_FIELD_ID          @"id"
#define DBQ_FIELD_DOMAIN      @"domain"
#define DBQ_FIELD_QID         @"qid"
#define DBQ_FIELD_DATA        @"data"
#define DBQ_FIELD_DATA2       @"data2"
#define DBQ_FIELD_DATA3       @"data3"
#define DBQ_FIELD_DATA4       @"data4"
#define DBQ_FIELD_DATA5       @"data5"
#define DBQ_FIELD_DATA6       @"data6"
#define DBQ_FIELD_STATUS      @"status"
#define DBQ_FIELD_UPTIME      @"updatetime"

@interface DBQueueItem : NSObject
- (id) initWithDictionary:(NSDictionary *)dict;
@property (nonatomic, assign) int ID;
@property (nonatomic, retain) NSString *domain;
@property (nonatomic, retain) NSString *qid;
@property (nonatomic, retain) NSString *key;
@property (nonatomic, retain) NSString *data;
@property (nonatomic, retain) NSString *data2;
@property (nonatomic, retain) NSString *data3;
@property (nonatomic, retain) NSString *data4;
@property (nonatomic, retain) NSString *data5;
@property (nonatomic, retain) NSString *data6;
@property (nonatomic, assign) int status;
@end

@interface DBQueue : Dao

/**
 *insert
 */
+ (BOOL) addQueue:(NSString *)qid withKey:(NSString *)key withDatas:(NSString *)data, ...;
+ (BOOL) addQueue:(NSString *)qid withKey:(NSString *)key withData:(NSString *)data;
+ (BOOL) addQueue:(NSString *)qid withData:(NSString *)data;

+ (DBQueueItem *) getOneItemByQueue:(NSString *)qid;
+ (DBQueueItem *) getOneItemByQueue:(NSString *)qid key:(NSString *)key;
+ (NSArray *) getAllItemsByQueue:(NSString *)qid;
+ (NSArray *) getAllItemsByQueue:(NSString *)qid itemClass:(Class)clazz;

+ (BOOL) setStatus:(int) status forId:(int)ID;
+ (BOOL) removeById:(int) ID;
+ (BOOL) removeByQueue:(NSString *)qid;
+ (BOOL) removeByQueue:(NSString *)qid key:(NSString *)key;
+ (BOOL) removeByField:(NSString *)field value:(NSString *)val;

+ (BOOL) updateField:(NSString *)field value:(NSString *)val forField:(NSString*)field2 value:(id)val2;
+ (BOOL) updateField:(NSString *)field value:(NSString *)val forId:(int)ID;
+ (BOOL) updateField:(NSString *)field value:(NSString *)val forQueue:(NSString *)qid key:(NSString *)key;
+ (BOOL) updateData:(NSString *)val forQueue:(NSString *)qid key:(NSString *)key;
@end

